/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.error;

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import org.jfonia.images.ImageConstants;
import org.jfonia.images.ScaledImageIcon;
import org.jfonia.language.LabelConstants;
import org.jfonia.language.LanguageResource;

/**
 *
 * @author Rik Bauwens
 */
public class ErrorConsole extends JDialog
{
        private static ErrorConsole instance;

        private ErrorConsole()
        {
                super();
                setVisible(false);
                setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
                setTitle(LanguageResource.getInstance().getLabel(LabelConstants.ERROR_CONSOLE));
                setIconImage(new ScaledImageIcon(ImageConstants.ERROR, "").
                        setMaximumSide(ImageConstants.FRAME_ICON_SIZE).getImageIcon().getImage());
                setAlwaysOnTop(true);
                final Console console = new Console();
                getContentPane().setLayout(new BorderLayout());
                JScrollPane contentPane = new JScrollPane(console.getConsole(),
                        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                getContentPane().add(contentPane, BorderLayout.CENTER);
                JButton copyButton = new JButton(LanguageResource.getInstance()
                        .getLabel(LabelConstants.COPY_TO_CLIPBOARD));
                copyButton.addActionListener(new ActionListener()
                {
                        public void actionPerformed(ActionEvent e)
                        {
                                Toolkit.getDefaultToolkit().getSystemClipboard()
                                        .setContents(new StringSelection(console.toString()), null);
                        }
                });
                getContentPane().add(copyButton, BorderLayout.SOUTH);
                pack();
        }

        public static synchronized ErrorConsole getInstance()
        {
                if(instance == null)
                        instance = new ErrorConsole();
                return instance;
        }
}
